import pytest
import openpyxl
import json

list_var = []
book = openpyxl.load_workbook("F:/Longlsland/sum.xlsx")
Sheet = book.active
Sheet["A1"].value = '加法'
Sheet["B1"].value = '求和'
Num = {
    '1+2': 3,
    '1+0': 1,
    '-1+1': 0,
    '1.0+2.0': 3,
}
row = 2
for num1, num2 in Num.items():
    Sheet.cell(row, 1).value = num1
    Sheet.cell(row, 2).value = num2
    row += 1
book.save("sum.xlsx")

for row in range(2, Sheet.max_row + 1):
    param = Sheet[f"A{row}"].value
    result = Sheet[f"B{row}"].value
    list_var.append((param, result))


def sum(a, b):
    return a + b


@pytest.mark.parametrize("test_input,expected", list_var)
def test_sum(test_input, expected):
    assert eval(test_input) == expected
